package com.yd.controller.yd;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;


public class YD_Users {
	//通过token查询用户信息
	public static JSONObject getUsersByToken(String token) throws MalformedURLException, IOException{
		String urlruls="http://192.168.2.116:8080/tianhui_users/app/users/token/getusers?key=yydd&token="+token;
		Document doc = Jsoup.parse(new URL(urlruls).openStream(), "UTF-8", urlruls);
		String str=doc.select("body").text().trim();
		JSONObject jso=JSON.parseObject(str);
		return jso;
	}
	//通过uid查询用户信息
	public static JSONObject getUsersByUid(String uid) throws MalformedURLException, IOException{
		String urlruls="http://192.168.2.116:8080/tianhui_users/app/users/uid/getusers?key=yydd&uid="+uid;
		Document doc = Jsoup.parse(new URL(urlruls).openStream(), "UTF-8", urlruls);
		String str=doc.select("body").text().trim();
		JSONObject jso=JSON.parseObject(str);
		return jso;
	}
	
	public static void main(String[] args) throws MalformedURLException, IOException {

		
		/*
		JSONObject yd_users_token=YD_Users.getUsersByToken(token);
		if(yd_users_token.getString("error").equals("1")){
			System.out.println(yd_users_token.getString("msg"));
		}
		JSONObject users_token=JSONObject.parseObject(yd_users_token.getString("data"));
		*/
		
		/*
		JSONObject yd_users_uid=YD_Users.getUsersByUid(uid);
		if(yd_users_uid.getString("error").equals("1")){
			System.out.println(yd_users_uid.getString("msg"));
		}
		JSONObject users_uid=JSONObject.parseObject(yd_users_uid.getString("data"));
		*/
		

		JSONObject yd_users_uid=YD_Users.getUsersByUid("20");
		if(yd_users_uid.getString("error").equals("1")){
			System.out.println(yd_users_uid.getString("msg"));
		}
		JSONObject users_uid=JSONObject.parseObject(yd_users_uid.getString("data"));
		
		System.out.println(users_uid.getString("phone"));
	}
}

















